package com.swak.generate.codegen;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * 创建代码：
 * mvnDebug com.github.618lf:swakx-generate:myPluginVersion:CodeGenerator
 *
 * @author lifeng
 */
@Mojo(name = "CodeGenerator", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
public class CodeGeneratorMojo extends AbstractMojo {

	@Parameter
	private String url;
	@Parameter
	private String userName;
	@Parameter
	private String passWord;
	@Parameter(defaultValue = "${project.groupId}")
	private String packageName;
	@Parameter
	private String generateDir;
	@Parameter
	private String generateModule;
	@Parameter
	private boolean generateAll = true;
	@Parameter
	private boolean fluxDrive = true;
	@Parameter
	private boolean report = false;

	public CodeGeneratorMojo() {

	}

	@Override
	public void execute() throws MojoExecutionException {
		CodeGenerator codeGenerator = new CodeGenerator(this.url, this.userName, this.passWord, this.packageName,
				this.generateDir, this.generateModule, this.generateAll, this.fluxDrive, report, null) {
			@Override
			protected void logInfo(String message) {
				CodeGeneratorMojo.this.getLog().info(message);
			}

			@Override
			protected void logError(String message, Exception e) {
				CodeGeneratorMojo.this.getLog().error(message, e);
			}
		};
		codeGenerator.execute();
	}
}
